package com.qf.springboot2.conditions;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

public class StuCondition implements Condition {

    /**
     *
     * @param context
     * @param metadata 获取当前类所在注解对象，进一步获取这个注解对象上的值
     * @return  表示条件是否成立，如果为false不成立，否则成立
     */
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        //获取PropertyCondition注解的属性键值对信息
        Map<String, Object> map = metadata.getAnnotationAttributes(PropertyCondition.class.getName());

        boolean useStu = (boolean) map.get("useStu");

        return useStu;
    }
}
